package Tools;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

import DiskManager.Disk;
import FileManager.SimulationFile;

import java.awt.*;
import java.awt.event.*;
public class Wordwin extends JFrame implements DocumentListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	JMenuBar menubar=new JMenuBar();
    JMenu file=new JMenu("文件");
    JTextArea wordArea=new JTextArea();
    JScrollPane imgScrollPane = new JScrollPane(wordArea);
    String [] str1={"保存"};
    Font f1=new Font("隶书",Font.PLAIN,15);
    SimulationFile simulationFile =  new SimulationFile();
    int flag=0;
    String source="";
    Disk disk; 
   
    public Wordwin(SimulationFile simulationFile,Disk myComputerControllerdisk){
       this.disk = myComputerControllerdisk;
       setTitle(simulationFile.getName());
 	   Toolkit kit = Toolkit.getDefaultToolkit();
 	   Dimension screenSize = kit.getScreenSize();//获取屏幕分辨率
 	   setSize(screenSize.width/2,screenSize.height/2);//大小
 	   setLocation(screenSize.width/4,screenSize.height/4);//位置
 	   add(imgScrollPane,BorderLayout.CENTER);
 	   setJMenuBar(menubar);
 	   file.setFont(f1);
 	   this.simulationFile =simulationFile;
 	   menubar.add(file);
        wordArea.setText(simulationFile.getContent());
 	   wordArea.getDocument().addDocumentListener(this);
 	   for(int i=0;i<str1.length;i++){
 		  JMenuItem item1= new JMenuItem(str1[i]);
 		  item1.addActionListener(new MyActionListener1());
 		  item1.setFont(f1);
 		  file.add(item1);
 	   }
 	
    }
    public void changedUpdate(DocumentEvent e) {
		flag=1;
	}
	
	public void insertUpdate(DocumentEvent e) {
		flag=1;
	}
	public void removeUpdate(DocumentEvent e) {
		flag=1;
	}
   
 
    void save(){
    	String text = wordArea.getText();
    	this.simulationFile.setContent(text);
    	this.simulationFile.saveContentArrary(disk); 
    }
   
   
    class MyActionListener1 implements ActionListener{
    	public void actionPerformed(ActionEvent e) {
    		if(e.getSource()instanceof JMenuItem){	
    			if(e.getActionCommand()=="保存"){
    				save();
    			}
    			
    		}
    		
    	}
    	   
}
}
